﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;

namespace WowGuildSite.Armory
{
    public enum ReputationCategory
    {
        Horde,
        HordeForces,
        Outland,
        ShattrathCity,
        SteamwheedleCartel,
        ZOther,
    }

    public enum ReputationKey
    {
        ThunderBluff,
        DarkspearTrolls,
        Orgrimmar,
        SilvermoonCity,
        Undercity,
        TheDefilers,
        FrostwolfClan,
        WarsongOutriders,
        TheConsortium,
        TheMaghar,
        CenarionExpedition,
        Netherwing,
        Sporeggar,
        Thrallmar,
        TheAldor,
        TheScryers,
        TheShatar,
        ShatariSkyguard,
        LowerCity,
        BootyBay,
        Everlook,
        Gadgetzan,
        Ratchet,
        Argentdawn,
        BloodsailBuccaneers,
        TheVioletEye,
        TheScaleOfTheSands,
        DarkmoonFaire,
        TimbermawHold,
        HydraxianWaterlords,
        KeepersOfTime,
        ShenDralar,
        ZandalarTribe,
        ThoriumBrotherhood,
        Tranquillien,
        CenarionCircle,
        AshTongueDeathSworn,
        Ogrila,
        BroodOfNozdormu,
        GelkisClanCentaur,
        MagramClanCentaur,
        Ravenholdt,
        WintersaberTrainers,
        Syndicate,
    }

    public enum ReputationStatus
    {
        Hated       = 0,
        Hostile     = 1,
        Unfriendly  = 2,
        Neutral     = 3,
        Friendly    = 4,
        Honored     = 5,
        Revered     = 6,
        Exalted     = 7,
    }

    public class ArmoryReputation
    {
        private ReputationKey               key;
        private ReputationCategory          category;
        private string                      localizedName;
        private string                      localizedCategory;
        private int                         reputationValue;

        public ReputationKey                Key
        {
            get { return key; }
        }

        public ReputationCategory           Category
        {
            get { return category; }
        }

        public string                       LocalizedName
        {
            get { return localizedName; }
        }

        public string                       LocalizedCategory
        {
            get { return localizedCategory; }
        }

        public int                          Value
        {
            get { return reputationValue; }
        }

        public ReputationStatus             Status
        {
            get
            {
                if (Value < -6000)
                {
                    return ReputationStatus.Hated;
                }
                else if (Value < -3000)
                {
                    return ReputationStatus.Hostile;
                }
                else if (Value < 0)
                {
                    return ReputationStatus.Unfriendly;
                }
                else if (Value < 3000)
                {
                    return ReputationStatus.Neutral;
                }
                else if (Value < 9000)
                {
                    return ReputationStatus.Friendly;
                }
                else if (Value < 21000)
                {
                    return ReputationStatus.Honored;
                }
                else if (Value < 42000)
                {
                    return ReputationStatus.Revered;
                }
                else
                {
                    return ReputationStatus.Exalted;
                }
            }
        }

        public bool                         IsHeroicKeyAvailable
        {
            get { return IsAtLeast(ReputationStatus.Revered); }
        }

        public bool                         IsAtLeast(ReputationStatus status)
        {
            return Status >= status;
        }

        internal static ArmoryReputation    FromElement(XmlElement element)
        {
            if (element == null)
            {
                return new ArmoryReputation();
            }

            ArmoryReputation reputation = new ArmoryReputation();

            XmlElement categoryElement      = (XmlElement)element.ParentNode;

            reputation.reputationValue      = ArmoryXmlUtility.GetElementAttributeInt(element, "reputation");
            reputation.key                  = (ReputationKey)Enum.Parse(typeof(ReputationKey), ArmoryXmlUtility.GetElementAttributeText(element,"key").Replace("\'",""),true );
            reputation.localizedName        = ArmoryXmlUtility.GetElementAttributeText(element, "name");
            reputation.category             = (ReputationCategory)Enum.Parse(typeof(ReputationCategory), ArmoryXmlUtility.GetElementAttributeText(categoryElement,"key").Replace("\'",""),true );
            reputation.localizedCategory    = ArmoryXmlUtility.GetElementAttributeText(categoryElement, "name");

            return reputation;
        }

        private ArmoryReputation()
        {
        }
    }
}
